<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/jsp/common/common.jsp"%>

<html>
<link rel="stylesheet" href="<%=contextPath%>/ext3/resources/css/ext-all.css" type="text/css"   />
<script src="<%=contextPath%>/ext3/adapter/ext/ext-base.js"></script>
<script src="<%=contextPath%>/ext3/ext-all.js"></script>
<link href="<%=contextPath%>/css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=contextPath%>/js/swfupload.js"></script>
<script type="text/javascript" src="<%=contextPath%>/js/swfupload.queue.js"></script>
<script type="text/javascript" src="<%=contextPath%>/js/fileprogress.js"></script>
<script type="text/javascript" src="<%=contextPath%>/js/handlers.js"></script>
<script type="text/javascript">
		var swfu;

		window.onload = function() {
			var settings = {
				flash_url : "<%=contextPath%>/js/swfupload.swf",
				upload_url: "<%=contextPath%>/file!upload.do",
				post_params: {"SESSID" : ""},
				file_size_limit : "600 MB",
				file_post_name: "uploadFile",   
				file_types : "*.*",
				file_types_description : "All Files",
				file_upload_limit : 100,
				file_queue_limit : 0,
				select_mode:'',
				
				custom_settings : {
					progressTarget : "fsUploadProgress",
					cancelButtonId : "btnCancel"
				},
				debug: false,

				// Button settings
				button_image_url: "images/TestImageNoText_65x29.png",
				button_width: "60",
				button_height: "25",
				button_placeholder_id: "spanButtonPlaceHolder",
				button_text: '<span class="theFont">上  传</span>',
				button_text_style: ".theFont { font-size: 14; };",
				button_text_left_padding: 12,
				button_text_top_padding: 3,
				
				// The event handler functions are defined in handlers.js
				file_queued_handler : fileQueued,
				file_queue_error_handler : fileQueueError,
				file_dialog_complete_handler : fileDialogComplete,
				upload_start_handler : uploadStart,
				upload_progress_handler : uploadProgress,
				upload_error_handler : uploadError,
				upload_success_handler : uploadSuccess,
				upload_complete_handler : endupload,
				queue_complete_handler : queueComplete	// Queue plugin event
			};

			swfu = new SWFUpload(settings);
	     };
	     
	     function endupload() {
	     	location.href = "<%= request.getContextPath()%>/file!getFileListByTableid.do";
	     }
	</script>
<script language="javascript">

			Ext.onReady(function(){
				var tb = new Ext.Toolbar({
			   		renderTo: document.all.tbar,
			    	items: [
				        {
				            text: '停止上传',
				            icon:"<%=contextPath%>/images/cross.png",
				            handler:function() {
				            	swfu.cancelQueue();
				            	//var win = window.open("<%=contextPath%>/jsp/common/uploadVedio.jsp","Result_window2","left=50,top=30,width=500,height=600,status=no,toolbar=no,autoscroll=yes,location=no,menubar=no,resizable=yes",true);
				            }
				       // },'-',
				       // {
				       //     text: '清空',
				       //     icon:"<%=contextPath%>/images/clear.png",
				      //      handler:function () {
				       //     	document.getElementById("frmFile").reset();
				       //     }
				        },'-', 
				        {
				            text: '关闭',
				            icon:"<%=contextPath%>/images/banjie.png",
				            handler:function () {
				            	parent.window.close();
				            }
				        },'->',
				        {
				            text: '上传界面',
				            icon:"<%=contextPath%>/images/down_bottom.gif",
				            handler:function () {
				            	if (content.style.display=="") {
	    							content.style.display="none";
				
								} else {
	    							content.style.display="";
								}	
				            }
				        }
				        
			    	]
			    });
			});

			String.prototype.endWith=function(str){
				if(str==null||str==""||this.length==0||str.length>this.length)
				return false;
				if(this.substring(this.length-str.length)==str)
					return true;
				else
					return false;
				return true;
			}
	
// 上传附件
function upload(){

		var imageflag = <%=session.getAttribute("imageflag")%>;

		if (document.getElementById("uploadFile").value == "") {
			alert("系统检测到您的提交有以下错误：\t\t\t\t\n 1:文件必须选择。");
			return false;
		} else if (imageflag =="1" && !document.getElementById("uploadFile").value.endWith("jpg")
				&& !document.getElementById("uploadFile").value.endWith("JPG")
				&& !document.getElementById("uploadFile").value.endWith("PNG")
				&& !document.getElementById("uploadFile").value.endWith("png")
				&& !document.getElementById("uploadFile").value.endWith("bmp")
				&& !document.getElementById("uploadFile").value.endWith("BMP")
				&& !document.getElementById("uploadFile").value.endWith("gif")
				&& !document.getElementById("uploadFile").value.endWith("GIF")
				){
			alert("系统检测到您的提交有以下错误：\t\t\t\t\n 1:图片必须选择以jpg、JPG、PNG、png、BMP、bmp、GIF、gif结尾的文件。");
			return false;
		}
		
		var frm = document.getElementById("frmFile");
		frm.action = "<%=contextPath%>/file!upload.do";//+ window.opener.document.getElementById("sb.id").value;
		frm.submit();
	//	Ext.MessageBox.show({ title:'请等待', icon:'<%=contextPath%>/images/save.gif',msg:'上传数据中……', width:240, progress:true, closable:false }); 
	}
	
	//var f = function(v){
	 //	return function(){		
	 /// 				Ext.MessageBox.updateProgress(v/10,''); 
	 // 	}
	// }; 
	  
	///for(var i=1;i<12;i++) { setTimeout(f(i),i*11000); } 
	
	// 浏览图片
	function openImage(id,name) {
		   document.getElementById("result").innerHTML = "";
		   var frm = document.getElementById("frmFile");
		   var str = "<%=contextPath%>/jsp/common/image.jsp?id=" + id;
  		   parent.addTab(name,str);

	}
	
	// 下载文件
	function downloadFile(id) {
		  document.getElementById("result").innerHTML = "";
		  document.getElementById("download").src = "<%=contextPath%>/file!fileDownload.do?id="+ id;
	}
	
	// 删除文件
    function deleteFile(id,trid){
    
    	document.getElementById("result").innerHTML = "";
    
    	if (confirm("确定要删除文件?")) {
    	
				Ext.Ajax.request( {
					method :'POST',
					url :'file!fileDelete.do?id='+ id,
					success : function(response) {
        				var mytable = document.getElementById("mybody");  
        				var myrow = document.getElementById(trid);   
       				    mytable.deleteRow(myrow.rowIndex-1);  
						
					},
					failure : function() {
						alert("删除失败");
					}
				});
		}
    }
	
/*
<c:if test="${!empty info}">
<c:choose>
    <c:when test="${info == 'OUTOFSIZE'}">
    	alert("上传失败，附件不能超过10M");
    	//parent.document.getElementById("result").innerHTML= "<font color='red'>上传失败，附件不能超过10M</font>";
    </c:when>
    <c:when test="${info eq 'ERROR'}">
    	alert("文件上传出现错误");
    	//parent.document.getElementById("result").innerHTML= "<font color='red'>文件上传出现错误</font>";
    </c:when>
    <c:when test="${info eq 'PATHERROR'}">
    	alert("没有指定上传路径");
    	//parent.document.getElementById("result").innerHTML= "<font color='red'>没有指定上传路径</font>";
    </c:when>
    <c:when test="${info eq 'DELETESUCCESS'}">
    	alert("删除成功");
    	//parent.document.getElementById("result").innerHTML= "<font color='red'>没有指定上传路径</font>";
    </c:when>
    
    <c:otherwise>
    	//document.getElementById("result").innerHTML= "<font color='red'>上传成功</font>";
    	//alert("上传成功");
    </c:otherwise>   
</c:choose>
</c:if>
*/
</script>
	<body>
		<div id ='tbar' ></div>
		<center><div id="result"><font color="red">${info}</font></div></center>
		<div id="content">
			<form id="frmFile" action="/file!upload.do" method="post" enctype="multipart/form-data">
				<div class="fieldset flash" id="fsUploadProgress">
					<span class="legend">上传中文件</span>
				</div>
				<div>
					<span id="spanButtonPlaceHolder"></span>
					<input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;display:none" />
				</div>
			</form>
		</div>
		
		
		
		<!--
			<table width="100%" id="contab">
				<tr>
					<th width="10%">
							选择文件：
					</th>
					<td width="90%">
						<s:file name="uploadFile" contentEditable="false" size="70" />
							&nbsp;&nbsp;&nbsp;
						
					</td>					
				</tr>
			
				<c:if test="${imageflag=='1'}">	
					<tr>
						<td align="left" width="100%"colspan="2"><img src="<%=contextPath%>/images/redlight.gif"/><font color="red">&nbsp;&nbsp;附件最大100M。
						<br><img src="<%=contextPath%>/images/redlight.gif"/>&nbsp;&nbsp;格式为JPG、jpg、PNG、png、BMP、bmp、GIF、gif 图片。</font>
					</td>
					</tr>
				</c:if>
				<c:if test="${imageflag=='0'}">	
					<tr>
						<td align="left" width="100%"colspan="2"><img src="<%=contextPath%>/images/redlight.gif"/><font color="red">&nbsp;&nbsp;附件最大100M。</font></td>
					</tr>
				</c:if>
			</table>
			-->
			<br>
			
			<table width="100%" id="listtab">
				<tr>
					<th class="ct" width="60%">文件名称</th>
					<th class="ct" width="20%" align="center">下载（<img src="<%=contextPath%>/images/diqu.png" >浏览）</th>
					<th class="ct" width="10%" align="center" >删除</th>
				</tr>
				 <tbody id="mybody">
				<c:forEach items="${fileList}" var="file" varStatus="status">
					<tr id='tr${status.index}'>
						<!--td><script language="javascript">document.write(parseInt('${status.index}') + parseInt(1))</script></td-->
						<td class="lf"><c:out value="${file.filename}"/><br></td>
						<td class="ct">
								<c:if test="${file.imageflag=='1'}">
									&nbsp;&nbsp;&nbsp;
								</c:if>
								<img style='cursor:pointer' alt="下载文件" onclick="downloadFile('${file.id}')" src="<%=contextPath%>/images/save.gif" >
								&nbsp;
								<c:if test="${file.imageflag=='1'}">
									<img style='cursor:pointer' alt="浏览图片" onclick="openImage('${file.id}','${file.filename}')" src="<%=contextPath%>/images/diqu.png" >
								</c:if>
						<br></td>
						<td class="ct"><img style='cursor:pointer' alt="删除文件" onclick="deleteFile('${file.id}','tr${status.index}')" src="<%=contextPath%>/images/delete.gif" ><br></td>
					</tr>
				</c:forEach>
				</tbody>
			</table>
			<iframe id="download" style="display:none"></iframe>
		</form>
	</body>
</html>